package com.free.front.bf;

import com.deco.dao.domain.table.CmsAdv;
import com.deco.domain.vo.store.StoreShopVo;
import com.deco.domain.vo.sys.ChinastatesVo;
import com.deco.domain.vo.sys.CmsAdvTypeVo;
import com.deco.domain.vo.sys.CmsAdvVo;
import com.deco.service.store.StoreShopService;
import com.deco.service.sys.ChinastatesService;
import com.deco.service.sys.CmsAdvService;
import com.deco.service.sys.CmsAdvTypeService;
import com.free.common.vo.ResultModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.persistence.Transient;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 功能概述:
 * </p>
 * <p>
 * 功能详述:
 * </p>
 */
public class BaseBf {
    /*========================================================================*
     *                         Public Fields (公共属性)
     *========================================================================*/

    /*========================================================================*
     *                         Private Fields (私有属性)
     *========================================================================*/
    @Autowired
    private CmsAdvTypeService advTypeservice;

    @Autowired
    private CmsAdvService advService;

    @Autowired
    private ChinastatesService chinaStateService;

    @Autowired
    private StoreShopService storeShopService;

    /*========================================================================*
     *                         Construct Methods (构造方法)
     *========================================================================*/



    /*========================================================================*
     *                         Public Methods (公有方法)
     *========================================================================*/

    public ChinastatesVo getChinastatesVo(String code){
        return chinaStateService.findByCode(code);
    }

    public List<CmsAdvVo> getCmsAvsByCode(String code){
        // banner
        CmsAdvTypeVo advType = advTypeservice.selectByCode(code);
        if(advType != null) {
            CmsAdvVo vo = new CmsAdvVo();
            vo.setTypeId(advType.getId());
            return advService.getCmsAdvVoList(vo, "idx asc");
        }
        return null;
    }

    public List<StoreShopVo> selProviceByStoreShop(int type){
        Map<String, ChinastatesVo> areaMap = chinaStateService.getAll();
        List<StoreShopVo> shopList = storeShopService.queryProvList(type);
        for(StoreShopVo shop : shopList){
            ChinastatesVo p = areaMap.get(shop.getProv());
            shop.setProvName(p.getName());
        }
        return shopList;
    }

    public List<StoreShopVo> selCityByStoreShop(int type, String prov){
        Map<String, ChinastatesVo> areaMap = chinaStateService.getAll();
        List<StoreShopVo> shopList = storeShopService.queryCityList(type, prov);
        ChinastatesVo p = areaMap.get(prov);
        for(StoreShopVo shop : shopList){
            ChinastatesVo c = p.getChildMap().get(shop.getCity());
            shop.setCityName(c.getName());
        }
        return shopList;
    }

    public List<StoreShopVo> selAreaByStoreShop(int type, String prov, String city){
        Map<String, ChinastatesVo> areaMap = chinaStateService.getAll();
        List<StoreShopVo> shopList = storeShopService.queryAreaList(type, city);
        ChinastatesVo p = areaMap.get(prov);
        ChinastatesVo c = p.getChildMap().get(city);
        for(StoreShopVo shop : shopList){
            ChinastatesVo a =  c.getChildMap().get(shop.getArea());
            shop.setAreaName(a.getName());
        }
        return shopList;
    }

    public ResultModel getAllChinaStates(){
        return ResultModel.success(chinaStateService.getAll());
    }
    /*========================================================================*
     *                         Private Methods (私有方法)
     *========================================================================*/
}
